package com.example.summary.thread;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class Test {


    private static class Result {
        String a;

        public String getA() {
            return a;
        }

        public void setA(String a) {
            this.a = a;
        }
    }

    private static class MyRunnable implements Runnable {

        Result result;

        public MyRunnable(Result result) {
            this.result = result;
        }

        @Override
        public void run() {
            System.out.println(result.getA());
            result.setA("2");
        }
    }

    public static void main(String[] args) throws Exception {
        ExecutorService fx = Executors.newFixedThreadPool(1);
//        Result result = new Result();
//        result.setA("1");
//        Future<Result> submit = fx.submit(new MyRunnable(result), result);
//        Result result1 = submit.get();
//        System.out.println(result.getA());
//
//
//
//        FutureTask<Integer> futureTask = new FutureTask<Integer>(() -> 1 + 1);
//        Future<?> submit1 = fx.submit(futureTask);
//        System.out.println(submit1.get());
//        System.out.println(futureTask.get());
//
//        MyCallable myCallable = new MyCallable();
//        System.out.println(myCallable.call());

//        fx.execute(() -> {
//            int x = 9 / 0;
//        });
//
//        Future<?> submit = Executors.newFixedThreadPool(1).submit(() -> {
//            int x = 9 / 0;
//            return 1;
//        });
//        submit.get();

//        List<FutureTask> futureTasks = new ArrayList<>();
//
//
//        for (int i = 0; i < 5; i++) {
//            FutureTask futureTask = new FutureTask(() ->
//                    send()
//            );
//            fx.submit(futureTask);
//            futureTasks.add(futureTask);
//        }
//
//        futureTasks.stream().forEach(r -> {
//            try {
//                Thread.sleep(5000L);
//                System.out.println(r.get());
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            } catch (ExecutionException e) {
//                e.printStackTrace();
//            }
//        });

//        Object o = submit.get();
//        System.out.println(String.valueOf(o));

        ThreadLocal<String> test = new InheritableThreadLocal<>();
        test.set("abc");

      new Thread(()->{
          System.out.println(test.get());
      }).start();
    }

    public static Integer send() {
        System.out.println(Instant.now());
        return 1;
    }


}
